<template>
  <div
    class="dv-border-box-7"
    :style="`box-shadow: inset 0 0 40px ${mergedColor[0]}; border: 1px solid ${mergedColor[0]}; background-color: ${backgroundColor}`"
    ref="borderBox7"
  >
    <svg class="dv-border-svg-container" :width="width" :height="height">
      <polyline class="dv-bb7-line-width-2" :stroke="mergedColor[0]" :points="`0, 25 0, 0 25, 0`" />
      <polyline class="dv-bb7-line-width-2" :stroke="mergedColor[0]" :points="`${width - 25}, 0 ${width}, 0 ${width}, 25`" />
      <polyline class="dv-bb7-line-width-2" :stroke="mergedColor[0]" :points="`${width - 25}, ${height} ${width}, ${height} ${width}, ${height - 25}`" />
      <polyline class="dv-bb7-line-width-2" :stroke="mergedColor[0]" :points="`0, ${height - 25} 0, ${height} 25, ${height}`" />

      <polyline class="dv-bb7-line-width-5" :stroke="mergedColor[1]" :points="`0, 10 0, 0 10, 0`" />
      <polyline class="dv-bb7-line-width-5" :stroke="mergedColor[1]" :points="`${width - 10}, 0 ${width}, 0 ${width}, 10`" />
      <polyline class="dv-bb7-line-width-5" :stroke="mergedColor[1]" :points="`${width - 10}, ${height} ${width}, ${height} ${width}, ${height - 10}`" />
      <polyline class="dv-bb7-line-width-5" :stroke="mergedColor[1]" :points="`0, ${height - 10} 0, ${height} 10, ${height}`" />
    </svg>

    <div class="border-box-content">
      <slot></slot>
    </div>
  </div>
</template>

<script>
import { cloneDeep, debounce, mergeDeep } from "../../../../utils/utils";
  import { onMounted, ref, watch } from "vue";

  export default {
    name: "DvBorderBox7",
    props: {
      color: {
        type: Array,
        default: () => ([])
      },
      backgroundColor: {
        type: String,
        default: "transparent"
      }
    },
    setup(props) {
      const borderBox7 = ref(null);
      const defaultColor = ref(['rgba(128,128,128,0.3)', 'rgba(128,128,128,0.5)']);
      const mergedColor = ref([]);
      const width = ref(300);
      const height = ref(300);
      const mergeColor = () => {
        mergedColor.value = mergeDeep(cloneDeep(defaultColor.value), props.color || []);
      };
      watch(() => props.color, s => {
        mergeColor();
      });
      onMounted(() => {
        const ro = new ResizeObserver(entries => {
          handleResize(entries);
        });
        ro.observe(borderBox7.value);
        mergeColor();
      });
      const handleResize = debounce((entries) => {
        width.value = entries[0].contentRect.width;
        height.value = entries[0].contentRect.height;
      }, 100);
      return { width, height, borderBox7, mergedColor, mergeColor, handleResize, defaultColor, };
    },
  };
</script>

<style scoped>
  .dv-border-box-7 {
    position: relative;
    width: 100%;
    height: 100%;
  }
  .dv-border-box-7 .dv-border-svg-container {
    position: absolute;
    top: 0px;
    left: 0px;
    width: 100%;
    height: 100%;
  }
  .dv-border-box-7 .dv-border-svg-container > polyline {
    fill: none;
    stroke-linecap: round;
  }
  .dv-border-box-7 .dv-bb7-line-width-2 {
    stroke-width: 2;
  }
  .dv-border-box-7 .dv-bb7-line-width-5 {
    stroke-width: 5;
  }
  .dv-border-box-7 .border-box-content {
    position: relative;
    width: 100%;
    height: 100%;
  }
</style>
